package com.springapi.controller;

import com.springapi.utils.HttpServiceHutool;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/kuaitongocr")
public class Kuaitongocr {
    //快瞳ocr运单号识别，注意加密手机号无法识别完整手机号
    @PostMapping("/ocr")
    public ResponseEntity<Map<String, Object>> kuaitongocr(@RequestParam String imgBase64) {
        // System.out.println("前台参数:"+imgBase64);
        // 创建一个Map来存储结果
        Map<String, Object> resultMap = new HashMap<>();

        //阿里云快瞳ocr接口地址
        String url = "http://waybill01.market.alicloudapi.com/s/api/ocr/waybill";

        try {
            //设置请求头
            Map<String, String> headers = new HashMap<>();
            headers.put("Authorization", "APPCODE " + "8509178a1fd44095b5b01b108eb92e24");
            headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
            Map<String, Object> params = new HashMap<>();
           // params.put("imgUrl", "");
            params.put("imgBase64", imgBase64);
            HttpServiceHutool h = new HttpServiceHutool();
            resultMap = h.sendPostRequest(url, params, headers);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        return ResponseEntity.ok(resultMap);
    }

}
